from typing import Callable, Any, Awaitable

from aiogram import BaseMiddleware
from aiogram.types import Message
from fluent.runtime import FluentLocalization


class L10nMiddleware(BaseMiddleware):
    def __init__(self, l10_local: FluentLocalization):
        self.l10_local = l10_local

    async def __call__(
            self,
            handler: Callable[[Message, dict[str, Any]], Awaitable[Any]],
            event: Message,
            data: dict[str, Any],
    ) -> Any:
        data['l10n'] = self.l10_local
        await handler(event, data)
